package com.yonyougov.devops.cruxcisupport.commitcontext;

import com.yonyougov.devops.cruxcisupport.commitcontext.dto.QueryCommitContextRequestDto;
import com.yonyougov.devops.cruxcisupport.commitcontext.vo.CommitContextVo;
import com.yonyougov.devops.fwc.api.dto.BaseResponseDto;
import com.yonyougov.devops.fwc.core.controller.CrudController;
import com.yonyougov.devops.fwc.core.service.BaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.math.BigInteger;
import java.util.List;

/**
 * Created by ligson on 2017/8/11.
 */
@Api(tags = "提测内容模块")
@RestController
@RequestMapping("/api/v2/commitcontext")
public class CommitContextController extends CrudController<CommitContextEntity, BigInteger> {

    private final CommitContextService commitContextService;

    public CommitContextController(CommitContextService commitContextService) {
        this.commitContextService = commitContextService;
    }

    @Override
    public BaseService<CommitContextEntity, BigInteger> getService() {
        return commitContextService;
    }

    //<!--用户自定义代码开始-->
    @ApiOperation(value = "提测内容查询", notes = "提测内容查询")
    @PostMapping(value = "/cc/context")
    public BaseResponseDto findCCDUVoByCommitTestId(@RequestBody @Valid QueryCommitContextRequestDto request) {
        BigInteger commitTestId = request.getCommitTestId();

        List<CommitContextVo> data = commitContextService.findListByCommitTestId(commitTestId);

        BaseResponseDto baseResponseDto = BaseResponseDto.getSuccessInstance();
        baseResponseDto.put("data", data);
        return baseResponseDto;
    }
    //<!--用户自定义代码结束-->
}
